//package com.yhy.consume.mq.listener;
//
//import cn.hutool.json.JSONUtil;
//import com.rabbitmq.client.Channel;
//import com.yhy.common.rabbitmq.config.DefaultDelayConfig;
//import com.yhy.common.rabbitmq.model.MessageData;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.amqp.core.Message;
//import org.springframework.amqp.rabbit.annotation.Argument;
//import org.springframework.amqp.rabbit.annotation.Exchange;
//import org.springframework.amqp.rabbit.annotation.Queue;
//import org.springframework.amqp.rabbit.annotation.QueueBinding;
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
//import org.springframework.stereotype.Component;
//
//import java.io.IOException;
//
//@Slf4j
//@Component
//@RequiredArgsConstructor
//public class DelayQueueConsumer {
//
//    @RabbitListener(bindings = {
//            @QueueBinding(
//                    value = @Queue(value = DefaultDelayConfig.DEFAULT_QUEUE, durable = "true"),
//                    exchange = @Exchange(value = DefaultDelayConfig.DEFAULT_EXCHANGE,
//                            durable = "true",
//                            type = "x-delayed-message",
//                            arguments = {@Argument(name = "x-delayed-type", value = "direct")}),
//                    key = {DefaultDelayConfig.DEFAULT_ROUTING_KEY},
//                    ignoreDeclarationExceptions = "true"
//            )})
//    @RabbitHandler
//    public void directHandlerManualAck(MessageData<Object> messageData, Message message, Channel channel) {
//        //  如果手动ACK,消息会被监听消费,但是消息在队列中依旧存在,如果 未配置 acknowledge-mode 默认是会在消费完毕后自动ACK掉
//        final long deliveryTag = message.getMessageProperties().getDeliveryTag();
//        try {
//            log.info("延迟队列插件，手动ACK，接收消息：{}", JSONUtil.toJsonStr(messageData));
//            // 通知 MQ 消息已被成功消费,可以ACK了
//            channel.basicAck(deliveryTag, false);
//        } catch (IOException e) {
//            try {
//                // 处理失败,重新压入MQ
//                channel.basicRecover();
//            } catch (IOException e1) {
//                e1.printStackTrace();
//            }
//        }
//    }
//}
//
